<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp '&#160;'>
]>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict">

	<xsl:template match="movie">
		<html>
			<head>
				<title>
					<xsl:value-of select="title"/>
					<xsl:if test="year and year != ''">
						<xsl:text> (</xsl:text>
						<xsl:value-of select="year"/>
						<xsl:text>)</xsl:text>
					</xsl:if>
				</title>
				<style>
body {
	background-color: #EBEBEB;
	margin: 6px;
	padding: 6px;
	border: 1px solid #848484;
	font-size: 65%;
	font-family: 'Trebuchet MS', Verdana, Georgia, Arial, sans-serif;
	min-height: 100px;
}

a, a:hover, a:visited {
	color: #FFAA00;
}

h1, h2, h3, h4, h5, h6 {
	margin: 0 0 10px 0;
	padding: 0;
	font-style: normal;
	font-weight: bold;
	font-variant: normal;
	color: #222;
}

h1 {
	font-size: 1.7em;
	margin-bottom: 0px;
}

h2 {
	font-size: 1.2em;
	margin-bottom: 20px;
	padding-bottom: 5px;
	border-bottom: 2px solid #222;
}

h3 {
	font-size: 1.4em;
	margin-bottom: 10px;
	border-bottom: 2px solid #222;
}

a.fakelink {
	cursor: none;
}

img#poster {
	max-width: 100px;
	padding: 2px;
	border: 1px solid #222;
	margin: 5px 0 10px 0;
}

table {
	margin-bottom: 20px;
}

table th, table td {
	text-align: left;
	vertical-align: top;
	font-size: 0.9em;
}

table th {
	padding-right: 10px;
	white-space: nowrap;
}

table.details th {
	background-color: #D2D2D2;
	border-bottom: 1px solid #222;
}

table.details .actor,
table.details .role {
	width: 20em;
}

table.details tr.odd td {
	background-color: #dedede;
}

#seen {
	width: 20px;
	height: 20px;
	display: block;
	background-color: transparent;
	background-repeat: no-repeat;
	background-image: url();
	float:right;
	position: relative;
	top: 0px;
}

#plot {
	font-size: 1.5em;
	font-family: "Times New Roman", serif;
	margin-bottom: 20px;
}

.imdb_url {
	padding-top: 13px !important;
}

#rating_out {
	margin-left: 8px;
	background-position: 0px 0px;
	position: absolute;
	width: 90px;
}

#rating_in {
	background-position: 0px -16px;
	width: 0pt;
}

#rating_out, #rating_in {
	height: 16px;
	background-color: transparent;
	background-image: url();
	background-repeat: no-repeat;
}

				</style>
			</head>
			<body>
				<xsl:if test="string(seen) = 'true'">
					<div id="seen" title="You have seen this movie"><span><!-- avoid tag collapsing --></span></div>
				</xsl:if>
				<h1>
					<xsl:value-of select="title"/>
					<xsl:if test="string(year)"> (<xsl:value-of select="year"/>)</xsl:if>
				</h1>
				<h2><xsl:if test="string(original-title) and string(original-title) != string(title)">
					(<xsl:value-of select="original-title"/>)
				</xsl:if><span><!-- avoid tag collapsing --></span></h2>
				
				<!-- Poster and main info -->
				<table cellspacing="0" border="0" id="main_info">
					<tr>
						<td width="110px">
							<xsl:choose>
								<xsl:when test="string(loaned) = 'true'">
									<img id="poster" src="" style="border: 0"></img>
								</xsl:when>
								<xsl:when test="string(poster)">
									<xsl:variable name="poster"><xsl:value-of select="poster"/></xsl:variable>
									<img id="poster" src="{$poster}"></img>
								</xsl:when>
								<xsl:otherwise>
									<img id="poster" src="" style="border: 0"></img>
								</xsl:otherwise>
							</xsl:choose>
							<xsl:choose>
								<xsl:when test="rating">
									<a href="movida://context/rating" class="fakelink">
									<div id="rating_out">
										<xsl:variable name="rating"><xsl:value-of select="rating"/></xsl:variable>
										<xsl:variable name="ratingw"><xsl:value-of select="$rating * 18" /></xsl:variable>
										<div id="rating_in" style="width:{$ratingw}" />
									</div>
									</a>
								</xsl:when>
								<xsl:otherwise>
									<div id="rating_out">
										<div id="rating_in" style="width:0" />
									</div>
								</xsl:otherwise>
							</xsl:choose>
						</td>
						<td>
							<table cellspacing="0" border="0" id="poster_side_info">
								<xsl:if test="directors">
								<tr>
									<th>Directed by:</th>
									<td>
										<xsl:for-each select="directors">
											<xsl:for-each select="person">
												<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
												<xsl:value-of select="name"/>
											</xsl:for-each>
										</xsl:for-each>
									</td>
								</tr>
								</xsl:if>
								<xsl:if test="producers">
								<tr>
									<th>Produced by:</th>
									<td>
										<xsl:for-each select="producers">
											<xsl:for-each select="person">
												<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
												<xsl:value-of select="name"/>
											</xsl:for-each>
										</xsl:for-each>
									</td>
								</tr>
								</xsl:if>
								<xsl:if test="running-time-string">
								<tr>
									<th>Running time:</th>
									<td>
										<xsl:value-of select="running-time-string"/>
									</td>
								</tr>
								</xsl:if>
								<xsl:if test="cast">
								<tr>
									<th>Starring:</th>
									<td>
										<xsl:for-each select="cast">
											<xsl:for-each select="person">
												<xsl:if test="position() &lt;= 6">
													<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
													<xsl:value-of select="name"/>
												</xsl:if>
											</xsl:for-each>
										</xsl:for-each>
										<xsl:text> (</xsl:text><a href="#cast">...</a><xsl:text>)</xsl:text>
									</td>
								</tr>
								</xsl:if>
								<xsl:if test="storage-id">
								<tr>
									<th>Storage ID:</th>
									<td>
										<xsl:value-of select="storage-id"/>
									</td>
								</tr>
								</xsl:if>
								<xsl:if test="imdb-url">
								<tr>
									<th colspan="2" class="imdb_url">
										<xsl:variable name="imdburl"><xsl:value-of select="imdb-url"/></xsl:variable>
										<a href="{$imdburl}">Movie page at IMDb</a>
									</th>
								</tr>
								</xsl:if>
							</table>
						</td>
					</tr>
				</table> <!-- poster and main info-->
				
				<h3>Details</h3>
				<table cellspacing="0" border="0" class="detailed_info">
					<xsl:if test="genres">
					<tr>
						<th>Genres:</th>
						<td>
						<xsl:for-each select="genres">
							<xsl:for-each select="genre">
								<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
								<xsl:value-of select="."/>
							</xsl:for-each>
						</xsl:for-each>
						</td>
					</tr>
					</xsl:if>
					<xsl:if test="languages">
					<tr>
						<th>Languages:</th>
						<td>
						<xsl:for-each select="languages">
							<xsl:for-each select="language">
								<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
								<xsl:value-of select="."/>
							</xsl:for-each>
						</xsl:for-each>
						</td>
					</tr>
					</xsl:if>
					<xsl:if test="countries">
					<tr>
						<th>Countries:</th>
						<td>
						<xsl:for-each select="countries">
							<xsl:for-each select="country">
								<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
								<xsl:value-of select="."/>
							</xsl:for-each>
						</xsl:for-each>
						</td>
					</tr>
					</xsl:if>
					<xsl:if test="tags">
					<tr>
						<th>Tags:</th>
						<td>
						<xsl:for-each select="tags">
							<xsl:for-each select="tag">
								<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
								<xsl:value-of select="."/>
							</xsl:for-each>
						</xsl:for-each>
						</td>
					</tr>
					</xsl:if>
				</table>
				
				<xsl:if test="string(plot)">
					<h3>Plot</h3>
					<div id="plot">
						<xsl:value-of select="plot" disable-output-escaping="yes" />
					</div>
				</xsl:if>
				
				<xsl:if test="cast">
					<a name="cast"></a>
					<h3>Cast</h3>
					<table class="details" cellspacing="0" border="0">
						<col class="actor"></col><col class="role"></col>
						<xsl:for-each select="cast">
							<xsl:for-each select="person">
								<xsl:choose>
									<xsl:when test="position() mod 2 = 0">
										<tr class="even"><td><xsl:value-of select="name"/></td><td>
											<xsl:for-each select="roles">
												<xsl:for-each select="role">
													<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
													<xsl:value-of select="."/>
												</xsl:for-each>
											</xsl:for-each>
										</td></tr>
									</xsl:when>
									<xsl:otherwise>
										<tr class="odd"><td><xsl:value-of select="name"/></td><td>
											<xsl:for-each select="roles">
												<xsl:for-each select="role">
													<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
													<xsl:value-of select="."/>
												</xsl:for-each>
											</xsl:for-each>
										</td></tr>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:for-each>
						</xsl:for-each>
					</table>
				</xsl:if>
				
				<xsl:if test="crew">
					<h3>Other crew members</h3>
					<table class="details" cellspacing="0" border="0">
						<col class="actor"></col><col class="role"></col>
						<xsl:for-each select="crew">
							<xsl:for-each select="person">
								<xsl:choose>
									<xsl:when test="position() mod 2 = 0">
										<tr class="even"><td><xsl:value-of select="name"/></td><td>
											<xsl:for-each select="roles">
												<xsl:for-each select="role">
													<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
													<xsl:value-of select="."/>
												</xsl:for-each>
											</xsl:for-each>
										</td></tr>
									</xsl:when>
									<xsl:otherwise>
										<tr class="odd"><td><xsl:value-of select="name"/></td><td>
											<xsl:for-each select="roles">
												<xsl:for-each select="role">
													<xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
													<xsl:value-of select="."/>
												</xsl:for-each>
											</xsl:for-each>
										</td></tr>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:for-each>
						</xsl:for-each>
					</table>
				</xsl:if>			
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
